class Hexagram {
  final String name;
  final String upperSymbol;
  final String lowerSymbol;
  final String description;
  final String upperElement;
  final String lowerElement;
  
  Hexagram({
    required this.name,
    required this.upperSymbol,
    required this.lowerSymbol,
    required this.description,
    required this.upperElement,
    required this.lowerElement,
  });
  
  String get fullSymbol => '$upperSymbol$lowerSymbol';
  
  String get elementRelation {
    // 简化的五行相生相克关系
    const Map<String, Map<String, String>> relations = {
      '金': {'金': '比和', '木': '克制', '水': '生发', '火': '克制', '土': '生发'},
      '木': {'金': '受克', '木': '比和', '水': '生发', '火': '生发', '土': '克制'},
      '水': {'金': '受生', '木': '受生', '水': '比和', '火': '克制', '土': '受克'},
      '火': {'金': '受克', '木': '受生', '水': '受克', '火': '比和', '土': '生发'},
      '土': {'金': '受生', '木': '受克', '水': '生发', '火': '受生', '土': '比和'},
    };
    
    if (relations.containsKey(upperElement) && 
        relations[upperElement]!.containsKey(lowerElement)) {
      return relations[upperElement]![lowerElement]!;
    }
    
    return '未知关系';
  }
  
  Map<String, dynamic> toMap() {
    return {
      'name': name,
      'upperSymbol': upperSymbol,
      'lowerSymbol': lowerSymbol,
      'description': description,
      'upperElement': upperElement,
      'lowerElement': lowerElement,
    };
  }
  
  factory Hexagram.fromMap(Map<String, dynamic> map) {
    return Hexagram(
      name: map['name'],
      upperSymbol: map['upperSymbol'],
      lowerSymbol: map['lowerSymbol'],
      description: map['description'],
      upperElement: map['upperElement'],
      lowerElement: map['lowerElement'],
    );
  }
}